package com.ruoyi.project.cms.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cms.domain.CmsMatter;
import com.ruoyi.project.cms.service.ICmsMatterService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 素材库Controller
 * 
 * @author ruoyi
 * @date 2020-10-09
 */
@RestController
@RequestMapping("/matter/matter")
public class CmsMatterController extends BaseController
{
    @Autowired
    private ICmsMatterService cmsMatterService;

    /**
     * 查询素材库列表
     */
    @PreAuthorize("@ss.hasPermi('matter:matter:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsMatter cmsMatter)
    {
        startPage();
        List<CmsMatter> list = cmsMatterService.selectCmsMatterList(cmsMatter);
        return getDataTable(list);
    }

    /**
     * 导出素材库列表
     */
    @PreAuthorize("@ss.hasPermi('matter:matter:export')")
    @Log(title = "素材库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CmsMatter cmsMatter)
    {
        List<CmsMatter> list = cmsMatterService.selectCmsMatterList(cmsMatter);
        ExcelUtil<CmsMatter> util = new ExcelUtil<CmsMatter>(CmsMatter.class);
        return util.exportExcel(list, "matter");
    }

    /**
     * 获取素材库详细信息
     */
    @PreAuthorize("@ss.hasPermi('matter:matter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsMatterService.selectCmsMatterById(id));
    }

    /**
     * 新增素材库
     */
    @PreAuthorize("@ss.hasPermi('matter:matter:add')")
    @Log(title = "素材库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsMatter cmsMatter)
    {
        return toAjax(cmsMatterService.insertCmsMatter(cmsMatter));
    }

    /**
     * 修改素材库
     */
    @PreAuthorize("@ss.hasPermi('matter:matter:edit')")
    @Log(title = "素材库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsMatter cmsMatter)
    {
        return toAjax(cmsMatterService.updateCmsMatter(cmsMatter));
    }

    /**
     * 删除素材库
     */
    @PreAuthorize("@ss.hasPermi('matter:matter:remove')")
    @Log(title = "素材库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsMatterService.deleteMatterByIds(ids));
    }
}
